package com.neusoft.controller;

import com.neusoft.pojo.Attend;
import com.neusoft.pojo.SysEmailInbox;
import com.neusoft.service.IEmailBoxService;
import com.neusoft.serviceImp.AttendServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@RequestMapping("/attend")
@RestController
@CrossOrigin
public class AttendController {
    @Autowired(required = false)
    AttendServiceImp attendServiceImp;
    //浏览所有记录
    @RequestMapping("/list")
    public List<Attend> list(){
        List<Attend> ad=attendServiceImp.attendanceList();
        for(Attend a:ad)
            System.out.println(a);
        return ad;
    }

    //签到
    @RequestMapping("/check")
    public boolean check(Attend attend){
        Date date = new Date();//获得系统时间.
        SimpleDateFormat sdf =   new SimpleDateFormat( " yyyy-MM-dd HH:mm:ss " );
        String nowTime = sdf.format(date);
        Timestamp time=Timestamp.valueOf(nowTime);
        attend.setAttendTime(time);
        attend.setUserId(1);
        System.out.println(attend.getAttendType());
        boolean flag=attendServiceImp.check(attend);
        return flag;
    }

    //变成Servlet类
    @RestController
    @RequestMapping("/email_box")
    @CrossOrigin
    public static class SysEmailBoxController {

        @Autowired(required = false)
        IEmailBoxService iEmailBoxService;

        @RequestMapping("listed")
        public List<SysEmailInbox> list(SysEmailInbox sysEmailInbox){
            return iEmailBoxService.sysEmailInboxList(sysEmailInbox);
        }

        @RequestMapping("delete")
        public boolean delete(int emailId){
            //删除应该是修改del_flag状态
            iEmailBoxService.sysEmailInboxdelete(emailId);
            return true;
        }

        @RequestMapping("trash_search")
        public List<SysEmailInbox> trash_list(SysEmailInbox sysEmailInbox){
            return iEmailBoxService.sysEmailTrashList(sysEmailInbox);
        }

        @RequestMapping("restore")
        public boolean restore(int emailId){
            //删除应该是修改del_flag状态
            iEmailBoxService.sysEmailTrashrestore(emailId);
            return true;
        }

        @RequestMapping("add")
        public boolean add_email(SysEmailInbox sysEmailInbox)
        {
            iEmailBoxService.sysEmailadd(sysEmailInbox);
            System.out.println(sysEmailInbox.getTitle()+","+sysEmailInbox.getSender()+","
                    +sysEmailInbox.getAttachment()+","+sysEmailInbox.getSendTime()+ ","+sysEmailInbox.getText());
            return true;
        }

        @RequestMapping("check_mail")
        public boolean check_mail(int emailId)
        {
            iEmailBoxService.sysEmailcheck(emailId);
            return true;
        }

        @RequestMapping("listed_check")
        public List<SysEmailInbox> list_check()
        {
            return iEmailBoxService.sysEmailcheckList();
        }

        @RequestMapping("saveEdit")
        public boolean saveEdit(SysEmailInbox sysEmailInbox)
        {
            iEmailBoxService.sysEmailsave(sysEmailInbox);
            System.out.println(sysEmailInbox.getTitle()+","+sysEmailInbox.getSender()+","
                    +sysEmailInbox.getAttachment()+","+sysEmailInbox.getSendTime()+ ","+sysEmailInbox.getText());
            return true;
        }
    }
}
